import {
  getToken,
  getUserId,
  removeAvatar,
  removeToken,
  removeUserId,
  removeRoleId,
  removeEmail
} from '@/utils/auth'
import { MessageBox } from 'element-ui'
import router from '../router'

// 判断是否登录
export function loginMessage() {
  if (getToken() === undefined || getUserId() === undefined) {
    MessageBox.confirm('请登录后再进行操作！', '未登录', {
      confirmButtonText: '去登录',
      cancelButtonText: '取消',
      type: 'warning'
    }).then(() => {
      removeAvatar()
      removeToken()
      removeUserId()
      removeRoleId()
      removeEmail()
      router.push({
        path: '/login',
        query: { redirect: location.hostname }
      })
    }).catch(() => {})
    return true
  }
  return false
}

